﻿using System;
using System.IO;
using System.Net;
using System.Text;

namespace RestfullTest
{
    class Restfull
    {
        public string Url { set; get; }

        private string method = "POST";
        public string Method { set { method = value; } get { return method; } }

        private string contentType = "application/x-www-form-urlencoded";
        public string ContentType { set { contentType = value; } get { return contentType; } }

        public string Query(string content)
        {
            try
            {
                HttpWebRequest request = HttpWebRequest.Create(Url) as HttpWebRequest;
                request.Method = this.Method;
                request.ContentType = this.ContentType;
                var stream = request.GetRequestStream();
                var buff = Encoding.ASCII.GetBytes(content);
                stream.Write(buff, 0, buff.Length);
                var response = request.GetResponse();
                var sr = new StreamReader(response.GetResponseStream());
                return sr.ReadToEnd();
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }
    }
}
